home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7479 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news2.near.net!ceylon!news
  2. From: Brenda <g051286>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is &Variable (declared as: char Variable[10])?
  5. Date: 26 Feb 1996 21:56:54 GMT
  6. Organization: GTE Laboratories Incorporated
  7. Message-ID: <4gtab6$acb@ceylon.gte.com>
  8. References: <4gqpa1$3h9@alcor.usc.edu> <4gsdno$1bg@umbc9.umbc.edu>
  9. NNTP-Posting-Host: 138.83.161.16
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.05 9000/735)
  14. X-URL: news://132.197.8.2/4gsdno$1bg@umbc9.umbc.edu
  15.  
  16. schlein@umbc.edu (Jonas J. Schlein) wrote:
  17. >Abu Wawda <wawda@alcor.usc.edu> wrote:
  18. >|> I'm having trouble understanding what the address of a static array
  19. >|> is.
  20. >
  21. >I'm having trouble understanding why it matters? You almost never use the
  22. >address of an array directly unless doing something tricky with pointers
  23. >or with particular dimensions of a multiple dimensional array.
  24. >
  25. >|> For example, if I declare a variable called myarray as:
  26. >|>     char myarray[10];
  27. >|> then what could &myarray possibly mean? myarray is not a pointer, so
  28. >|> &myarray could not possibly be the address of the variable myarray
  29. >|> (like it would be if I did char* myarray and then asked for &myarray).
  30. >
  31. >Yes it could and yes it is...'myarray' is not a pointer, but &myarray is
  32. >a pointer to 'myarray'.
  33.  
  34. Um, that's not correct.  myarray is DEFINITELY a pointer!  As declared above,
  35. it is a constant pointer to 10 contiguous char datatypes.  myarray is an
  36. ADDRESS whereas *(myarray + 5) or myarray[5] is the 6th element in the array.
  37. The difference between an array and something like "char *p=myarray", is that
  38. you can say p++, but you can't say myarray++.  You shouldn't say &myarray
  39. either because myarray is a constant, but I read that on some compilers
  40. scanf ignores the dereferencing and does not bother to warn you.
  41.  
  42. Hope this helps.
  43.  
  44. Brenda
  45.  
  46.